package monopoly;

import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

public class Card 
{
	private String message;
	private int moveToSpace;
	private String moveToNearest;
	private int moveSpaces;
	private boolean collect200;
	private double paymentAmount;
	private String payee;
	private boolean getOutOfJail;
	private int rentMultiplier;
	private int diceRollMultiplier;
	private String type;
		
	public Card()
	{
		this.message = "";
		this.moveToSpace = 100;
		this.moveToNearest = "";
		this.moveSpaces = 0;
		this.collect200 = false;
		this.paymentAmount = 0.0;
		this.payee = "";
		this.getOutOfJail = false;
		this.rentMultiplier = 0;
		this.diceRollMultiplier = 0;
	}
	
	public Card(String message, int moveToSpace, boolean collect200)
	{
		this.message = message;
		this.moveToSpace = moveToSpace;
		this.collect200 = collect200;
		
		this.moveToNearest = "";
		this.moveSpaces = 0;
		this.paymentAmount = 0.0;
		this.payee = "";
		this.getOutOfJail = false;
		this.rentMultiplier = 0;
		this.diceRollMultiplier = 0;
	}
	
	public Card(String message, int moveSpaces)
	{
		this.message = message;
		this.moveSpaces = moveSpaces;
		
		this.moveToSpace = 100;
		this.collect200 = false;
		this.paymentAmount = 0.0;
		this.payee = "";
		this.getOutOfJail = false;
		this.moveToNearest = "";
		this.rentMultiplier = 0;
		this.diceRollMultiplier = 0;
	}
	
	
	
	public Card(String message, String moveToNearest, boolean collect200, int rentMultiplier, int diceRollMultiplier)
	{
		this.message = message;
		this.moveToNearest = moveToNearest;
		this.collect200 = collect200;
		this.rentMultiplier = rentMultiplier;
		this.diceRollMultiplier = diceRollMultiplier;
		
		this.moveSpaces = 0;
		this.moveToSpace = 100;
		this.paymentAmount = 0.0;
		this.payee = "";
		this.getOutOfJail = false;
		
	}
	
	// If paymentAmount is positive, active player receives payment.
	// If paymentAmount is negative, active player makes payment.
	public Card(String message, double paymentAmount, String payee)
	{
		this.message = message;
		this.paymentAmount = paymentAmount;
		this.payee = payee;
		
		this.moveToNearest = "";
		this.collect200 = false;
		this.moveSpaces = 0;
		this.moveToSpace = 100;
		this.getOutOfJail = false;
	}
	
	public Card(String message, boolean getOutOfJail)
	{
		this.message = message;
		this.getOutOfJail = getOutOfJail;
		
		this.paymentAmount = 0.0;
		this.payee = "";
		this.moveToNearest = "";
		this.collect200 = false;
		this.moveSpaces = 0;
		this.moveToSpace = 100;
	}
	

	
	public String getMessage()
	{
		return message;
	}
	
	public int getMoveToSpace()
	{
		return moveToSpace;
	}
	
	public int getMoveSpaces()
	{
		return moveSpaces;
	}
	
	public String getMoveToNearest()
	{
		return moveToNearest;
	}
	
	public int moveSpaces()
	{
		return moveSpaces;
	}
	
	public boolean getCollect200()
	{
		return collect200;
	}
	
	public double getPaymentAmount()
	{
		return paymentAmount;
	}
	
	public String getPayee()
	{
		return payee;
	}
	
	public boolean getOutOfJail()
	{
		return getOutOfJail;
	}
	
	public int getRentMultiplier()
	{
		return rentMultiplier;
	}
	
	public int getDiceRollMultiplier()
	{
		return diceRollMultiplier;
	}
	
	public void setType(String type)
	{
		this.type = type;
	}
	
	public void execute(GameState gameState)
	{
		Player activePlayer = gameState.getActivePlayer();
		Player inactivePlayer = gameState.getInactivePlayer();
		ImageIcon icon;
		
		if (type.equals("Chance"))
			icon = new ImageIcon("images/drawCard/chance.png", "Chance");
		else
			icon = new ImageIcon("images/drawCard/communityChest.png", "Community Chest");
		JOptionPane.showMessageDialog(null, message, type, JOptionPane.PLAIN_MESSAGE, icon);
		
		if (getOutOfJail())
			activePlayer.addGetOutOfJailCard();
		
		if (payee == "Bank")
			activePlayer.adjustBalance(paymentAmount);
		
		if (payee == "Player")
		{
			activePlayer.adjustBalance(paymentAmount);
			inactivePlayer.adjustBalance(0-paymentAmount);
		}
		
		if (moveToSpace != 100)
			activePlayer.move(collect200, moveToSpace);
		
		if (moveSpaces != 0)
			activePlayer.move(moveSpaces, collect200);
		
		if (!(moveToNearest).equals(""))
			activePlayer.move(moveToNearest);
	}
}


